﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Logout : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // if user cookie exists
        if (Request.Cookies["userInfo"] != null)
        {
            // delete token saved in application variable
            Application[Request.Cookies["userInfo"]["username"] as string] = null;
            // create a new cookie
            HttpCookie myCookie = new HttpCookie("userInfo");
            // set expiration day to some time in the past
            myCookie.Expires = DateTime.Now.AddDays(-1d);
            // replace newly created cookie with existed one, thus logging out user
            Response.Cookies.Add(myCookie);
        }
        Response.Redirect("/Login.aspx");
    }
}